/*
 * @Author      : 小蜜蜂 84537795@qq.com
 * @Date        : 2022-06-08 11: 48: 17
 * @LastEditTime: 2023-06-02 16:00:19
 * @LastEditors: 小蜜蜂 84537795@qq.com
 * @Description : 
 * @FilePath: /handheld-terminal-app/lib/widget/common/top_bar.dart
 * @CopyRight：小蜜蜂🐝  QQ：834537795
 */
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class TopBar extends StatefulWidget implements PreferredSizeWidget {
  final PreferredSizeWidget bottom;
  final String title;
  final List<Widget> actions;
  final TextStyle titleStyle;
  final Color backgroundColor;
  final String backImgName;
  final bool isBack;
  final Brightness brightness;
  final double height;
  TopBar(
      {this.bottom,
      this.title,
      this.actions,
      this.titleStyle,
      this.backgroundColor,
      this.backImgName,
      this.isBack = false,
      this.brightness,
      this.height = 45});
  @override
  _TopBarState createState() => _TopBarState();

  @override
  Size get preferredSize =>
      Size.fromHeight(this.bottom != null ? 91 : this.height);
}

class _TopBarState extends State<TopBar> {
  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: false);

    return AppBar(
      centerTitle: true, // 标题居中
      brightness: widget.brightness,
      leading: GestureDetector(
        onTap: () {
          Navigator.pop(context);
        },
        child: Container(
          padding: EdgeInsets.fromLTRB(0.w, 32.w, 35.w, 32.w),
          child: Image.asset(
            'assets/arrow_return.png',
            width: 17.w,
          ),
        ),
      ),
      title: new Text(
        widget.title ?? '',
        style: widget.titleStyle ??
            new TextStyle(
              color: Colors.white,
              fontSize: 17.0,
            ),
      ),
      backgroundColor: widget.backgroundColor ?? Color(0xFF297CFF),
      elevation: 0,
      bottom: widget.bottom,
      actions: widget.actions,
    );
  }
}

class AppBarBottom extends StatelessWidget implements PreferredSizeWidget {
  final Widget child;
  AppBarBottom({
    this.child,
  });
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        children: <Widget>[
          Container(
            width: double.infinity,
            height: 1,
            color: Color(0xFFE5E5E5),
          ),
          child ??
              SizedBox(
                height: 0,
              ),
        ],
      ),
    );
  }

  @override
  Size get preferredSize => Size.fromHeight(this.child != null ? 47 : 1);
}
